// 规则引擎功能测试脚本
async function testRuleEngine() {
  console.log('开始测试规则引擎功能...');
  
  try {
    // 测试获取规则
    console.log('\n1. 测试获取规则:');
    const rulesResponse = await fetch('http://localhost:3004/api/rules');
    if (rulesResponse.ok) {
      const rules = await rulesResponse.json();
      console.log('规则列表:', rules);
    } else {
      console.log('❌ 获取规则失败:', rulesResponse.status);
    }
    
    // 测试获取变量
    console.log('\n2. 测试获取变量:');
    const variablesResponse = await fetch('http://localhost:3004/api/variables');
    if (variablesResponse.ok) {
      const variables = await variablesResponse.json();
      console.log('变量列表:', variables);
    } else {
      console.log('❌ 获取变量失败:', variablesResponse.status);
    }
    
    // 测试添加规则
    console.log('\n3. 测试添加规则:');
    const newRule = {
      name: '测试规则',
      description: '测试规则描述',
      condition: {
        variable: 'DB1,W0',
        operator: '===',
        value: 1
      },
      actions: [
        {
          type: 'log',
          message: '测试规则触发'
        }
      ]
    };
    
    const addRuleResponse = await fetch('http://localhost:3004/api/rules', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(newRule)
    });
    
    if (addRuleResponse.ok) {
      const result = await addRuleResponse.json();
      console.log('✅ 添加规则成功:', result);
    } else {
      console.log('❌ 添加规则失败:', addRuleResponse.status);
    }
    
    console.log('\n✅ 规则引擎测试完成!');
  } catch (error) {
    console.error('❌ 测试过程中出现错误:', error);
  }
}

// 运行测试
testRuleEngine();